const Common = require('./common');
const moment = require('moment');

class Demo extends Common {
  constructor() {
    super('Demo');
    this.add = this.add.bind(this);
    this.edit = this.edit.bind(this);
    this.list = this.list.bind(this);
  }

  async add(ctx) {
    let {
      username,
      age
    } = ctx.params;
    let result = await this.insert({
      username,
      age,
    })

    ctx.body = {
      code: '666',
      msg: 'ok',
      result
    };
  }



  async edit(ctx) {
    ctx.body = 'edit';
  }

  async list(ctx) {
    let date = moment().format("YYYY-MM-DD");
    let res = await this.find({
      time: {
        $gt: new Date(date)
      }
    });
    ctx.body = res;
  }
}

module.exports = new Demo();
